<h1 id="json-object">JSON Object</h1>
<p>JSON Object功能基本与js一致。</p>
<h3 id="初始化">初始化</h3>
<pre><code class="hljs language-javascript"><span class="hljs-comment">// way 1</span>
obj = {}

<span class="hljs-comment">// way 2</span>
obj = {<span class="hljs-attr">name</span>:<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">88</span>}

<span class="hljs-comment">// way 3</span>
color = <span class="hljs-string">&quot;strawberry&quot;</span>
obj = {
    <span class="hljs-attr">name</span>: <span class="hljs-string">&quot;car&quot;</span>,
    <span class="hljs-attr">special</span>: <span class="hljs-string">&quot;carry&quot;</span>,
    <span class="hljs-attr">food</span>: <span class="hljs-string">&quot;oil&quot;</span>,
    <span class="hljs-attr">colors</span>: [<span class="hljs-string">&quot;red&quot;</span>, color, <span class="hljs-string">&quot;black&quot;</span>]
}
</code></pre>
<h3 id="键值数量获取">键值数量获取</h3>
<pre><code class="hljs language-javascript">obj = {<span class="hljs-attr">name</span>:<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">88</span>}
<span class="hljs-title function_">println</span>(obj.<span class="hljs-title function_">size</span>()) <span class="hljs-comment">// 2</span>
</code></pre>
<h3 id="键值添加">键值添加</h3>
<pre><code class="hljs language-javascript">obj = {}
<span class="hljs-comment">// way 1</span>
obj[<span class="hljs-string">&quot;name&quot;</span>] = <span class="hljs-string">&quot;jerry&quot;</span>
<span class="hljs-comment">// way 2</span>
obj.<span class="hljs-property">age</span> = <span class="hljs-number">3</span>
<span class="hljs-title function_">println</span>(obj) <span class="hljs-comment">// {&quot;name&quot;:&quot;jerry&quot;, &quot;age&quot;:3}</span>
</code></pre>
<h3 id="值修改">值修改</h3>
<pre><code class="hljs language-javascript">obj = {<span class="hljs-string">&quot;name&quot;</span>:<span class="hljs-string">&quot;jerry&quot;</span>, <span class="hljs-string">&quot;age&quot;</span>:<span class="hljs-number">3</span>}
<span class="hljs-comment">// way 1</span>
obj[<span class="hljs-string">&quot;name&quot;</span>] = <span class="hljs-string">&quot;tom&quot;</span>
<span class="hljs-comment">// way 2</span>
obj.<span class="hljs-property">age</span> = <span class="hljs-number">18</span>
<span class="hljs-title function_">println</span>(obj) <span class="hljs-comment">// {&quot;name&quot;:&quot;tom&quot;, &quot;age&quot;:18}</span>
</code></pre>
<h3 id="键值删除">键值删除</h3>
<pre><code class="hljs language-javascript">obj = {<span class="hljs-attr">name</span>:<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">88</span>}
obj.<span class="hljs-title function_">remove</span>(<span class="hljs-string">&quot;age&quot;</span>)
<span class="hljs-title function_">println</span>(obj) <span class="hljs-comment">// {&quot;name&quot;:&quot;tom&quot;}</span>
</code></pre>
<h3 id="判断是否包含相应键">判断是否包含相应键</h3>
<pre><code class="hljs language-javascript">obj = {<span class="hljs-attr">name</span>:<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">88</span>}
<span class="hljs-title function_">println</span>(obj.<span class="hljs-title function_">contain</span>(<span class="hljs-string">&quot;name&quot;</span>)) <span class="hljs-comment">// true</span>
<span class="hljs-title function_">println</span>(obj.<span class="hljs-title function_">contain</span>(<span class="hljs-string">&quot;addr&quot;</span>)) <span class="hljs-comment">// false</span>
</code></pre>
<h3 id="遍历">遍历</h3>
<pre><code class="hljs language-javascript">obj = {<span class="hljs-attr">name</span>:<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">88</span>}
foreach k, v : obj {
    <span class="hljs-title function_">println</span>(k, v)
}
</code></pre>
<p>输出</p>
<pre><code>age 88
name tom
</code></pre>
<h2 id="json-object-方法">JSON Object 方法</h2>
<table>
<thead>
<tr>
<th>方法</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>size()</td>
<td>键值对数量</td>
</tr>
<tr>
<td>remove(key)</td>
<td>根据指定键移除键值对</td>
</tr>
<tr>
<td>contain(key))</td>
<td>判断是否包含相应键</td>
</tr>
</tbody></table>
